﻿using System;
using System.Collections.Generic;
using System.Text;
using WebApiV1.Data.Entity;
using WebApiV1.Domain.Enum;
using WebApiV1.Inteface.Log;

namespace WebApiV1.Utils.Log
{
    //帮助类
    public static class LogHelper
    {
        //静态方法
        //this拓展方法
        public static void Logger(this ILog log,Exception exception,LogsLevel logsLevel,int userId)
        {
            var item = new Logs
            {
                LogLevel=(int)logsLevel,
                ShoreMessage=exception.Message,
                FullMessage=exception.ToString(),
                UserId=userId
            };
            log.Insert(item);
        }

        public static void Info(this ILog log, Exception exception, LogsLevel logsLevel = LogsLevel.信息, int userId = 0)
        {
            Logger(log, exception, logsLevel, userId);
        }

        public static void Debug(this ILog log, Exception exception, LogsLevel logsLevel = LogsLevel.调试, int userId=0)
        {
            Logger(log, exception, logsLevel, userId);
        }

        public static void Warn(this ILog log, Exception exception, LogsLevel logsLevel = LogsLevel.警告, int userId = 0)
        {
            Logger(log, exception, logsLevel, userId);
        }

        public static void Error(this ILog log, Exception exception, LogsLevel logsLevel = LogsLevel.错误, int userId = 0)
        {
            Logger(log, exception, logsLevel, userId);
        }

        public static void Fatal(this ILog log, Exception exception, LogsLevel logsLevel = LogsLevel.崩溃, int userId = 0)
        {
            Logger(log, exception, logsLevel, userId);
        }
    }
}
